package java01_type;

import common.enums.WeekEnum;
import common.util.EnumUtil;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class Test09_Enum {

    @Test
    public void testWeekEnum() {
        WeekEnum[] values = WeekEnum.values();
        for (WeekEnum value : values) {
            System.out.println(value.ordinal() + " -> " + value.name() + " -> " + value.getValue() + " -> " + value.getDesc());
        }
    }

    @Test
    public void testValueOf() {
        WeekEnum weekEnum = WeekEnum.valueOf("Mon");
        System.out.println(weekEnum.getDesc());
    }

    @Test
    public void testValueOfError() {
        WeekEnum weekEnum = WeekEnum.valueOf("ERROR");
        System.out.println(weekEnum.getDesc());
    }

    @Test
    public void testGetByValue() {
        Optional<WeekEnum> byValue = EnumUtil.getByValue(WeekEnum.class, 1);
        byValue.ifPresent(System.out::println);
    }

    @Test
    public void testGetByDesc() {
        Optional<WeekEnum> byDesc = EnumUtil.getByDesc(WeekEnum.class, "周一");
        byDesc.ifPresent(System.out::println);
    }

    @Test
    public void testValueDescMap() {
        Map<Integer, String> valueDescMap = EnumUtil.getValueDescMap(WeekEnum.class);
        valueDescMap.forEach((k, v) -> {
            System.out.println(k + " -> " + v);
        });
    }

    @Test
    public void testNameDescMap() {
        Map<String, String> nameDescMap = EnumUtil.getNameDescMap(WeekEnum.class);
        nameDescMap.forEach((k, v) -> {
            System.out.println(k + " -> " + v);
        });
    }

    @Test
    public void testGetEnumList() {
        List<Map<String, Object>> enumList = EnumUtil.getEnumList(WeekEnum.class);
        for (Map<String, Object> map : enumList) {
            System.out.println(map);
        }
    }
}
